package com.lagou.niancheng.rpc.server.zookeeper;

import com.lagou.niancheng.rpc.server.SimpleRpcMethod;
import org.springframework.beans.BeanUtils;

import java.lang.reflect.InvocationTargetException;

/**
 * com.lagou.niancheng.rpc.server.zookeeper.ZooKeeperRpcMethod
 *
 * @author 大犬
 * @date 2020/5/20
 */
public class ZooKeeperRpcMethod extends SimpleRpcMethod {
    private RefreshResponseTimeScheduler refreshResponseTimeScheduler;
    private SimpleRpcMethod simpleRpcMethod;

    public ZooKeeperRpcMethod(SimpleRpcMethod simpleRpcMethod, RefreshResponseTimeScheduler refreshResponseTimeScheduler) {
        BeanUtils.copyProperties(simpleRpcMethod, this);
        this.simpleRpcMethod = simpleRpcMethod;
        this.refreshResponseTimeScheduler = refreshResponseTimeScheduler;
    }

    @Override
    public Object invoke(Object... params) throws InvocationTargetException, IllegalAccessException {
        Object result = simpleRpcMethod.invoke(params);
        // 刷新响应时间
        refreshResponseTimeScheduler.refresh(System.currentTimeMillis());
        return result;
    }
}
